<?php
/**
 * Introduction: 物流公司逻辑
 * @author: 杨陈鹏
 * @date: 2016/4/05 16:04
 * @email: yangchenpeng@cdlinglu.com
 */

namespace Common\Logic;

use Common\Model;

class ExpressLogic
{

    static public $model;

    public function __construct()
    {

        self::$model = new Model\ExpressModel();

    }

    /**
     * Introduction: 获取数据
     * @author: 杨陈鹏
     * @date: 2016/4/05 16:04
     * @email: yangchenpeng@cdlinglu.com
     * @param $where array 查询条件
     */
    public function getData($where, $fields = '*', $order = 'order_by asc',$page = 1,$nums = 20)
    {

        $data = self::$model
            ->where($where)
            ->order($order)
            ->field($fields)
            ->page($page,$nums)
            ->select();

        $total  = self::$model
            ->where($where)
            ->count();

        return ['code' => 200, 'data' => $data ,'total' => $total];

    }

    /**
     * Introduction: 获取数据
     * @author: 杨陈鹏
     * @date: 2016/4/05 16:04
     * @email: yangchenpeng@cdlinglu.com
     * @param $where array 修改条件
     * @param $data array 需要修改的数据
     */
    public function update($where, $data)
    {

        if (!$where || !$data)
            return ['code' => 300, 'msg' => '参数错误'];

        if (self::$model->where($where)->save($data))
            return ['code' => 200, 'msg' => '更新成功', 'data' => ['where' => $where, 'data' => $data]];


        return ['code' => 300, 'msg' => '更新失败'];

    }


}